package com.bjc.platform.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bjc.platform.model.AdmCode;
import com.bjc.platform.repository.AdmCodeRepo;
import com.bjc.platform.service.AdmCodeService;

/**
 * 
 * AdmCode业务逻辑处理器实现类
 * 
 */
@Service("admCodeService")
public class AdmCodeServiceImpl extends BaseServiceImpl implements AdmCodeService {
	@Autowired
	/** AdmCode持久层实现 */
	private AdmCodeRepo admCodeRepo;

	/**
	 * 根据adm_code.code查询对应的子类别代码表数据
	 * 
	 * @param code
	 *            代码
	 * 
	 * @return 返回查询结果 List<AdmCode>
	 */
	@Override
	public List<AdmCode> queryChildrenByCode(String code) {
		return admCodeRepo.queryChildrenByCode(code);
	}

	public AdmCode getAdmCode(String id) {
		return admCodeRepo.findOne(Integer.parseInt(id));
	}

	@Override
	public AdmCode getByCode(String code) {
		return admCodeRepo.findByCode(code);
	}

	@Override
	public AdmCode queryCodeWithCodeAndParentCode(String code, String parentCode) {
		List<AdmCode> codes= admCodeRepo.queryCodeByCodeAndParentCode(code, parentCode);
		if(codes!=null&&!codes.isEmpty()){
			return codes.get(0);
		}else{
			return null;
		}
	}

}
